//
//  NSDictionary+Test.m
//  MKUITestApp
//
//  Created by 苏尚进 on 2024/11/22.
//  Copyright © 2024 moon. All rights reserved.
//

#import "NSDictionary+Test.h"
#import <MKUI/MKUI.h>
@implementation NSDictionary (Test)
- (UIEdgeInsets)test_UIEdgeInsetsForKeyPath:(NSString *)keypath otherwise:(UIEdgeInsets)other{
    NSDictionary *json = [self mk_dictionaryForKeyPath:keypath];
    if(!json) return other;
    UIEdgeInsets value = other;
    value.top = [json mk_floatForKeyPath:@"top" otherwise:value.top];
    value.bottom = [json mk_floatForKeyPath:@"bottom" otherwise:value.bottom];
    value.left = [json mk_floatForKeyPath:@"left" otherwise:value.left];
    value.right = [json mk_floatForKeyPath:@"right" otherwise:value.right];
    return value;
}
+ (NSDictionary *)test_UIEdgeInsets:(UIEdgeInsets)value{
    NSDictionary *json = @{
       @"top":@(value.top),
       @"bottom":@(value.bottom),
       @"left":@(value.left),
       @"right":@(value.right),
    };
    return json;
}
- (CGSize)test_CGSizeForKeyPath:(NSString *)keypath otherwise:(CGSize)other{
    NSDictionary *json = [self mk_dictionaryForKeyPath:keypath];
    if(!json) return other;
    CGSize value = other;
    value.width = [json mk_floatForKeyPath:@"width" otherwise:value.width];
    value.height = [json mk_floatForKeyPath:@"height" otherwise:value.height];
    return value;
}
+ (NSDictionary *)test_CGSize:(CGSize)value{
    NSDictionary *json = @{
        @"width":@(value.width),
        @"height":@(value.height),
    };
    return json;
}
- (UIColor *)test_UIColorForKeyPath:(NSString *)keypath otherwise:(UIColor *)other{
    NSString *hex = [self mk_stringForKeyPath:keypath];
    UIColor *value = [UIColor mk_colorWithString:hex];
    return value?:other;
}
@end
